from bbtracker import BBTracker
from cmd import Cmd
import sys

class CmdInterpreter(Cmd):
    def __init__(self):
        Cmd.__init__(self)
        
        # Create and start the tracker.
        self._tracker = BBTracker()
        self._tracker.start()
        
    def do_exit(self, args):
        print "Shutting down tracker...",
        self._tracker.shutdown()
        self._tracker.join()
        print "done"
        sys.exit(0)

cmdint = CmdInterpreter()
try:
    cmdint.cmdloop("Welcome to BBTracker.")
except KeyboardInterrupt:
    print "Keyboard interrupt caught. Shutting down tracker...",
    cmdint._tracker.shutdown()
    cmdint._tracker.join()
    print "done"
